<?php
  
  class JooS_Session {
    const iv =  '12345673';
    const key256 = '1234567890123456ABCDEFGHIJKLMNOP';

    private $mcrypt = null;

    protected function pack($value) {
      $s = serialize($value);
      return $s . md5($s);
    }

    protected function unpack($value) {
      $s = rtrim($value, chr(0));
      $s = substr($s, 0, strlen($s)-32);
      return unserialize($value);
    }
    
    public function encode($original) {
      mcrypt_generic_init($this->mcrypt, self::key256, self::iv);
      $encoded = mcrypt_generic($this->mcrypt, $this->pack($original));
      mcrypt_generic_deinit($this->mcrypt);

      return base64_encode($encoded);
    }

    public function decode($crypted) {
      mcrypt_generic_init($this->mcrypt, self::key256, self::iv);
      $decrypted = mdecrypt_generic($this->mcrypt, base64_decode($crypted));
      mcrypt_generic_deinit($this->mcrypt);

      return $this->unpack($decrypted);
    }
    
    public function __construct() {
      $this->mcrypt = mcrypt_module_open(MCRYPT_BLOWFISH, '', MCRYPT_MODE_CBC, '');
    }

    public function __destruct() {
      mcrypt_module_close($this->mcrypt);
    }
  }

  $s = new JooS_Session();
  $o = 534; // array(  534, 'Covex', 'qwerty'  );
  $e = $s->encode($o);
  $d = $s->decode($e);

  echo "<pre>" . var_export(array(
    $o, 
    array($e, strlen($e)), 
    $d, 
  ), true) . "<pre>";

?>